package io.demo.message.serial;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class FastjsonSerializedObject<T> extends SerializedObject<T> {

  FastjsonSerializedObject(T object) {
    super(object);
  }

  @Override
  protected void beforeSerialize() {
    // doing nothing
  }

  @Override
  protected byte[] doSerialization(T object) {
    return JSON.toJSONBytes(object, SerializerFeature.EMPTY);
  }

  @Override
  public T reverse() {
    return JSON.parseObject(getByteArray(), getObjectClass(),
        Feature.AllowUnQuotedFieldNames, Feature.AllowComment, Feature.AllowArbitraryCommas,
        Feature.AllowISO8601DateFormat, Feature.AllowSingleQuotes);
  }
}
